﻿using System;
using System.Data;
using Dapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RFC.DB.UnitTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestConnection()
        {
            IDbConnection connection =
                DB.ConnectionFactory.CreateSqlConnection(
                    @"server=192.168.117.167;database=Test.Dapper;user id=test;password=t#@!$%;");
            var result = connection.Execute("INSERT INTO [Person] (ID,Name,Age) VALUES (@ID,@Name,@Age)", new { ID = Guid.NewGuid(), Name = "小李", Age = 23 });
            Assert.AreEqual(result, 1);
        }

        [TestMethod]
        public void TestQueryFirst()
        {
            IDbConnection connection =
                DB.ConnectionFactory.CreateSqlConnection(
                    @"server=192.168.117.167;database=Test.Dapper;user id=test;password=t#@!$%;");
            var persion = connection.QueryFirstOrDefault<Person>("SELECT TOP 1 * FROM [Person]");
            Assert.IsNotNull(persion);
        }
    }

    public class Person
    {
        public Guid ID { get; set; }
        public string Name { get; set; }
        public byte Age { get; }
    }
}
